package thread;


/**
 * 中断异常
 * 当一个sleep()方法处于睡眠阻塞的过程中，如果此时的interrupt()方法被调用，
 * 那么就会抛出InterruptedException异常，
 */
public class SleepDemo2 {
    public static void main(String[] args) {

        Thread lin = new Thread(() -> {
            System.out.println("睡一觉！");
            try {
                Thread.sleep(100000);
            }catch (InterruptedException e){
                System.out.println("干嘛呢？干嘛呢？都破了相了");
            }
            System.out.println("睡醒了！");
        });

        Thread huang = new Thread(()->{
            System.out.println("大锤80，小锤40");
            for(int i =0;i<5;i++){
                try{
                    System.out.println("八十！");
                    Thread.sleep(1000);
                }catch (InterruptedException e){
                    System.out.println(e.getMessage());
                }

            }
            System.out.println("打完了！");
            lin.interrupt(); // 提前中断lin的线程，引发异常，执行System.out.println("干嘛呢？干嘛呢？都破了相了");
        });

        lin.start();
        huang.start();


    }
}
